# 把用'$'分割的文件转换成json格式

import sys
import json

if len(sys.argv) != 2:
    print('Usage:\n    ts.py <input file>\n')
    exit(1)

with open(sys.argv[1], encoding='UTF-8') as f:
    line_num = 0
    while True:
        try:
            line = f.readline()
            line_num += 1
            if line == '':
                break
            line = line.strip()
            if line == '':
                print('')
                continue
            if line[0] == '#':
                print(line)
                continue
            s = line.split('$')
            if len(s) < 6:
                print('error at line:%d'%(line_num))
                continue
            s[3] = s[3].strip()
            print('%s`w=%s`g=%s`pn=%s`m=%s`t=%s'%(s[0], s[1], s[2], s[3], s[4], s[5]))
        except:
            print('line:', line_num)
            print(line)
